<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/29 0029
 * Time: 9:59
 */

namespace App\FreeBird\Controllers\Home;

use App\Base\Controllers\Controller;
use App\FreeBird\Contracts\CollectionInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;


class CollectionController extends Controller
{

    /**
     * 获取收藏接口
     * @return CollectionInterface
     */
    public function getCollectionInterface(){
        return app()->make(CollectionInterface::class);
    }

    /***
     * 收藏
     * @param Request $request
     * @return mixed
     * @throws \App\Base\Exceptions\ApiException
     */
    public function setCollectionInfo(Request $request){
        $validator = Validator::make($request->all(), [
            'collection_id' => 'required',
            'collection_type' => 'required',
        ]);
        if ($validator->fails()) {
            //$error=$validator->errors()->getMessages();
            $this->throwValidatorException($validator);
        }
        return $this->getCollectionInterface()->setCollection($request->except("token"));
    }

    /**
     * 获取收藏列表
     * @param Request $request
     */
    public function getCollectionList(Request $request){
        $validator = Validator::make($request->all(), [
            'collection_type' => 'required',
        ]);
        if ($validator->fails()) {
            //$error=$validator->errors()->getMessages();
            $this->throwValidatorException($validator);
        }
        return $this->getCollectionInterface()->getCollection($request->except("token"));
    }

}